﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Album_Inherit:SqlInteractionBase
    {
        #region 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllBySoftID(object id)
        {

            string sSql = "select Album_ID from t_Album where Album_Software_ID='"+id+"'";
            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }
        #endregion


        public object GetAlbumContent(object id)
        {

            string sSql = "select Album_Content from t_Album where Album_Software_ID='" + id + "'";
            SqlCommand cmd = new SqlCommand(sSql, _mainConnection);

            object bytes = null;

            try
            {
                _mainConnection.Open();
                //if (_mainConnectionIsCreatedLocal)
                //{
                //    _mainConnection.Open();
                //}
                //else
                //{
                //    if (_mainConnectionProvider.IsTransactionPending)
                //    {
                //        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                //    }
                //}

                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    bytes = (byte[])dr["Album_Content"];

                }
                dr.Close();

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmd.Dispose();


            }

            return bytes;
        }


    }
}
